package com.fxu.tpl.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import com.fxu.tpl.enums.ProjectTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/***
 * <p>fxu</p>
 * 项目表：[project]的数据实体类
 * @author fangxu
 * @version 2019-09-23
 ***/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Project", description = "项目")
@TableName("fxu_project")
public class Project extends SEntity<Project> implements Serializable {
/*=== 自动生成代码 开始 ===*/
    private static final long serialVersionUID = -805495552969454470L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "项目名", required = true)
    @NotBlank(message = "项目名必须赋值")
    @Size(max = 16, message = "项目名的长度必须小于16位")
    private String name;

    @ApiModelProperty(value = "项目类型[1:spring-boot,2:spring-cloud,3:spring-dubbo]", required = true)
    @NotNull(message = "项目类型必须赋值")
    @EnumValid(target = ProjectTypeEnum.class, message = "项目类型的值必须为{1:spring-boot,2:spring-cloud,3:spring-dubbo}")
    private Integer type;

    @ApiModelProperty(value = "项目注释", required = true)
    @NotBlank(message = "项目注释必须赋值")
    @Size(max = 64, message = "项目注释的长度必须小于64位")
    private String cmmt;

    @ApiModelProperty(value = "项目作者", required = true)
    @NotBlank(message = "项目作者必须赋值")
    @Size(max = 32, message = "项目作者的长度必须小于32位")
    private String author;

    @ApiModelProperty(value = "项目公司", required = true)
    @NotBlank(message = "项目公司必须赋值")
    @Size(max = 32, message = "项目公司的长度必须小于32位")
    private String company;

    @ApiModelProperty(value = "模板类名", required = true)
    @NotBlank(message = "模板类名必须赋值")
    @Size(max = 32, message = "模板类名的长度必须小于32位")
    private String tplClass;

    @ApiModelProperty(value = "模板模块", required = true)
    @NotBlank(message = "模板模块必须赋值")
    @Size(max = 32, message = "模板模块的长度必须小于32位")
    private String tplModule;

    @ApiModelProperty(value = "模板项目", required = true)
    @NotBlank(message = "模板项目必须赋值")
    @Size(max = 32, message = "模板项目的长度必须小于32位")
    private String tplProject;

    @ApiModelProperty(value = "模板地址", required = true)
    @NotBlank(message = "模板地址必须赋值")
    @Size(max = 255, message = "模板地址的长度必须小于255位")
    private String tplPath;

    @ApiModelProperty(value = "模板客户层", required = true)
    @NotBlank(message = "模板客户层必须赋值")
    @Size(max = 32, message = "模板客户层的长度必须小于32位")
    private String tplRest;

    @ApiModelProperty(value = "模板中间层", required = true)
    @NotBlank(message = "模板中间层必须赋值")
    @Size(max = 32, message = "模板中间层的长度必须小于32位")
    private String tplFacade;

    @ApiModelProperty(value = "模板服务层", required = true)
    @NotBlank(message = "模板服务层必须赋值")
    @Size(max = 32, message = "模板服务层的长度必须小于32位")
    private String tplService;

    @ApiModelProperty(value = "目标地址", required = true)
    @NotBlank(message = "目标地址必须赋值")
    @Size(max = 255, message = "目标地址的长度必须小于255位")
    private String dstPath;

    @ApiModelProperty(value = "前端地址", required = true)
    @NotBlank(message = "前端地址必须赋值")
    @Size(max = 255, message = "前端地址的长度必须小于255位")
    private String vuePath;

    @ApiModelProperty(value = "前端模板", required = true)
    @NotBlank(message = "前端模板必须赋值")
    @Size(max = 255, message = "前端模板的长度必须小于255位")
    private String vueTpl;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态[1:正常,0:删除]")
    @EnumValid(target = StatusEnum.class, message = "状态的值必须为{1:正常,0:删除}")
    private Integer status;

    @TableField(fill = UPDATE, update = "%s+1")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @Valid
    @TableField(exist = false)
    @ApiModelProperty(value = "字段")
    @Cascade(thisField = "id", linkField = "projectId", save = true)
    private List<Module> moduleList;

    public String getTypeText() {
        return ProjectTypeEnum.desc(type);
    }
    public String getStatusText() {
        return StatusEnum.desc(status);
    }
/*=== 自动生成代码 结束 ===*/
    
    @JsonIgnore
    public String getDstProject() {
    	return name;
    }
}
